<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * create articlecounter-code for articledetailpages
 * get: articlecounter.tpl.php
 * used from article.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
$productNumber = intval(db::getInstance()->rawQuery("SELECT count(*) FROM product " .
		"WHERE product_category = '" . $result['product_category'] . "'"));
//$productNumber = $productNumberx[0]['count(*)'];

$cols = Array('product_id', 'product_name');
db::getInstance()->where('product_category', $result['product_category']);
db::getInstance()->orderBy('product_order', 'ASC');
$productIds = db::getInstance()->get("product", null, $cols);

if (db::getInstance()->count <= 0)
{ 
	$refPage->assign('articlecounterprevious', FALSE);
}
else
{
	$refPage->assign('articlecounter', TRUE);
	$bufferId = '';

	db::getInstance()->where('product_id', $title);
	$productIdsx = db::getInstance()->getOne('product', null, 'product_order');
	
	$cols = Array('product_id', 'product_name');
	db::getInstance()->where('product_order', $productIdsx['product_order'], '<');
	db::getInstance()->where('product_category', $result['product_category']);
	db::getInstance()->where('product_active', '1');
	db::getInstance()->orderBy('product_order', 'DESC');
	$productIds = db::getInstance()->getOne('product', null, $cols);
	$refPage->assign('peviouspage', '');

	if (db::getInstance()->count >= 1)
	{
		$refPage->assign('peviouspage',
			'<a href="/index.php?page=article&title=' . $productIds['product_id'] .
			'&name=' . $productIds['product_name'] . '" title="' .
			$productIds['product_name'] . '">' . $productIds['product_name'] . '</a>');
		$refPage->assign('articlecounterprevious', TRUE);
	}
	else
	{
		$refPage->assign('articlecounterprevious', FALSE);
	}

	/*
	  $productIds = db::getInstance()->rawQuery(
	  "SELECT product_id, product_name FROM product " .
	  "WHERE product_order > ( SELECT product_order FROM product WHERE product_id = '" .
	  $title . "' ) AND product_category ='" . $result['product_category'] . "' " .
	  "AND product_active = '1' " . "ORDER BY product_order ASC limit 0,1");
	 */

	db::getInstance()->where('product_id', $title);
	$productIdsx = db::getInstance()->getOne('product', null, 'product_order');
	
	$cols = Array('product_id', 'product_name');
	db::getInstance()->where('product_order', $productIdsx['product_order'], '>');
	db::getInstance()->where('product_category', $result['product_category']);
	db::getInstance()->where('product_active', '1');
	db::getInstance()->orderBy('product_order', 'ASC');
	$productIds = db::getInstance()->getOne('product', null, $cols);
	$refPage->assign('nextpage', '');

	if (db::getInstance()->count >= 1)
	{
		$refPage->assign('nextpage',
			'<a href="/index.php?page=article&title=' . $productIds['product_id'] .
			'&name=' . $productIds['product_name'] . '" title="' .
			$productIds['product_name'] . '">' . $productIds['product_name'] . '</a>');
		$refPage->assign('articlecounternext', TRUE);
	}
	else
	{
		$refPage->assign('articlecounternext', FALSE);
	}
}
?>